@extends('layouts.application')

@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户列表</strong> /
                    <small>User List</small>
                </div>
            </div>

            <hr>

            @include('layouts.shared._flash')

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{{route('system.user.create')}}" class="am-btn am-btn-default"><span
                                        class="am-icon-plus"></span> 新增
                            </a>
                        </div>
                    </div>
                </div>

                <div class="am-u-sm-12 am-u-md-3">
                    <form method="get">
                        <div class="am-input-group am-input-group-sm">
                            <input type="text" class="am-form-field" name="keyword"
                                   value="{{Request::input('keyword')}}">
                            <span class="am-input-group-btn">
                            <button class="am-btn am-btn-default" type="submit">搜索</button>
                        </span>
                        </div>
                    </form>
                </div>

            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" class="check_all"/>
                                </th>
                                <th>编号</th>
                                <th>用户名</th>
                                <th>所属用户组</th>
                                <th>邮箱</th>
                                <th>电话</th>
                                <th>创建时间</th>
                                <th>账号状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>


                            @foreach($users as $user)
                                <tr data-id="{{$user->id}}">
                                    <td>
                                        <input type="checkbox" name="ids[]" value=""
                                               class="checked_id"/>
                                    </td>
                                    <td>{{$user->id}}</td>
                                    <td>{{$user->name}}</td>
                                    <td>{{$user->roles->implode('name',', ')}}</td>
                                    <td>{{$user->email}}</td>
                                    <td>{{$user->mobile}}</td>
                                    <td>{{$user->created_at}}</td>
                                    <td>
                                        {!! is_something($user,'is_status') !!}
                                    </td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a href="{{route('system.user.edit',$user->id)}}"
                                                   class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                            class="am-icon-pencil-square-o"></span> 编辑
                                                </a>

                                                @if($user->id != 1)
                                                    <a href="javascript:void (0);"
                                                       class="delete am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                        <span class="am-icon-trash"></span> 删除
                                                    </a>
                                                @endif

                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach

                            </tbody>
                        </table>
                    </form>

                    <div class="am-cf">
                        共 {{$users->total()}} 条记录

                        <div class="am-cf">
                            <div class="am-fr">
                                {!! $users->appends(Request::all())->links() !!}
                            </div>
                        </div>
                    </div>
                    <hr/>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>


    </div>
@endsection
@section('js')
    <script>
        $(function () {
            //删除文章
            $('.delete').click(function () {
                var id = $(this).parents('tr').data('id');
                var _this = $(this);
                $.ajax({
                    type: 'DELETE',
                    url: "/admin/system/user/" + id,
                    data: {id: id},
                    success: function () {
                        _this.parents('tr').fadeOut(400);
                    }
                })
                return false;
            })

            //启用禁用账号
            $('.change_attr').click(function () {
                var id = $(this).parents('tr').data('id');
                var attr = $(this).data('attr');
                var _this = $(this);
                $.ajax({
                    type: 'PATCH',
                    url: '{{route('system.user.change')}}',
                    data: {id: id, attr: attr},
                    success: function () {
                        _this.toggleClass('am-icon-check am-icon-close');
                    }
                })
                return false;
            })
        });
    </script>
@endsection